﻿using System;
using System.Collections.Generic;
using System.Text;
using XiaoGang.Soft.XGWMS.COM;
using XiaoGang.Soft.XGWMS.MODEL;
using XiaoGang.Soft.XGWMS.DAL_SQL;

namespace XiaoGang.Soft.XGWMS.BLL
{
    public class BLL_M013_STORAGE_OUTPUT
    {
        XGWMS.DAL_SQL.DAL_M009_STORAGE_INPUT dal_M009_STORAGE_INPUT = 
            new XiaoGang.Soft.XGWMS.DAL_SQL.DAL_M009_STORAGE_INPUT();
        XGWMS.DAL_SQL.DAL_M013_STORAGE_OUTPUT dal_M013_STORAGE_OUTPUT = 
            new XiaoGang.Soft.XGWMS.DAL_SQL.DAL_M013_STORAGE_OUTPUT();
        XGWMS.DAL_SQL.DAL_M010_BILL dal_M010_BILL = 
            new XiaoGang.Soft.XGWMS.DAL_SQL.DAL_M010_BILL();
        private readonly XiaoGang.Soft.XGWMS.DAL_SQL.DAL_ComProcess dal_ComProcess = 
            new XiaoGang.Soft.XGWMS.DAL_SQL.DAL_ComProcess();
        private readonly XiaoGang.Soft.XGWMS.BLL.BLL_ComProcess bll_ComProcess =
            new BLL_ComProcess ();

        /// <summary>	
        /// <p><b>方法名称</b>InitComBoxProcess</p>	
        /// <p><b>概要説明  :</b>仓库编号的初始化</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/09</p>	
        /// <p><b>修改历史:</b></p>	
        /// </summary>
        /// <returns type="ReturnValue">仓库编号和仓库名称</returns>
        public ReturnValue InitComBoxProcess()
        {
            return dal_M009_STORAGE_INPUT.Init_Combox();
        }

        /// <summary>
        /// <p><b>方法名称</b>GetBillID</p>
        /// <p><b>概要説明  :</b>取得货单番号</p>
        /// <p><b>作成者	:</b>万岗</p>
        /// <p><b>作成日	:</b>2008/09/09</p>
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <param name="model">采番条件</param>
        /// <returns type="string">番号</returns>
        public string GetBillID(MODEL.MOD_M010_BILL model)
        {            
            #region 採番

            //ReturnValue returnValue;
            //MOD_M011_GET_ID modGetID = new MOD_M011_GET_ID();
            //modGetID.UPDATER_ID = model.UPDATER_ID;
            //modGetID.TERMINAL_CD = model.TERMINAL_CD;
            //modGetID.GETID_DIV = "05";
            //modGetID.FISCAL_YEAR = System.DateTime.Now.Year.ToString("####");
            //returnValue = bll_ComProcess.GetSlipID(modGetID);
            //if (!returnValue.ErrorFlag)
            //{
            //    return returnValue.ErrorID;
            //}
            //return returnValue.ResultDataSet.Tables[0].Rows[0]["SLIPID"].ToString().Trim();

            string UniqueNo = string.Empty;
            if (!DAL_ComProcess.GetUniqueNo(model.UPDATER_ID
                , model.TERMINAL_CD
                , "05"
                , System.DateTime.Now.Year.ToString("####")
                , out UniqueNo))
            {
                return "E11003";
            }
            return UniqueNo;
            #endregion
        }

        /// <summary>	
        /// <p><b>方法名称</b>CheckUnits</p>	
        /// <p><b>概要説明  :</b>商品数量的Check</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/09</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strConstrolName">检索条件</param>	
        /// <returns type="ReturnValue">商品数量信息</returns>
        public ReturnValue CheckUnits(MODEL.MOD_M009_STORAGE_INPUT model)
        {
            return dal_M013_STORAGE_OUTPUT.GetSingleGoods(model);
        }

        /// <summary>	
        /// <p><b>方法名称</b>UpdateStorageProcess</p>	
        /// <p><b>概要説明  :</b>商品出库</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/09</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strConstrolName">出库信息</param>	
        /// <returns type="string">执行结果信息</returns>
        public string UpdateStorageProcess(MODEL.MOD_M009_STORAGE_INPUT model)
        {
            ReturnValue rvReturnValue = dal_M013_STORAGE_OUTPUT.SubGoodsCount(model);
            if (rvReturnValue.IsSuccess == false)
            {
                return rvReturnValue.ErrorID;
            }
            return "0";
        }

        /// <summary>	
        /// <p><b>方法名称</b>InsertProcess</p>	
        /// <p><b>概要説明  :</b>库存的插入</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/09</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="string" param="strConstrolName">商品信息</param>	
        /// <returns type="string">执行结果信息</returns>
        public string InsertProcess(MODEL.MOD_M010_BILL model)
        {
            ReturnValue returnValue;

            returnValue = dal_M010_BILL.GetSingleData(model);
            if (returnValue.IsSuccess == false)
            {
                return returnValue.ErrorID;
            }
            if (0 != returnValue.ResultDataSet.Tables[0].Rows.Count)
            {
                return "W11E01";//本[@]已经存在。
            }

            returnValue = dal_M010_BILL.InsertProcess(model);
            if (returnValue.IsSuccess == false)
            {
                return returnValue.ErrorID;
            }
            return "0";
        }
    }
}
